package com.atguigu.cmsservice.service.impl;

import com.atguigu.cmsservice.entity.Banner;
import com.atguigu.cmsservice.mapper.BannerMapper;
import com.atguigu.cmsservice.service.BannerService;
import com.atguigu.commonutils.R;
import com.atguigu.servicebase.handler.GuliException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-11-28
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {

    @Autowired
    private BannerService bannerService;


    @Override
    public void pageBanner(Page<Banner> pageParam, Object o) {

    }

    @Override
    public Banner getBannerById(String id) {
        return null;
    }

    //添加
    @Override
    public void saveBanner(Banner banner) {
        int insert = baseMapper.insert(banner);

    }

    //更改
    @Override
@CacheEvict(value = "banner", key = "'selectIndexList'")
public void updateBanner(Banner banner) {
    baseMapper.updateById(banner);
}





    @Override
    @Cacheable(value = "banner", key = "'selectIndexList'")
//k-v k=value+key  :  "banner::selectIndexList"
    public List<Banner> getAllBanner() {
        List<Banner> list = baseMapper.selectList(null);

        return list;
    }

    //删除
    @Override
    public void removeBannerById(String id) {
        int delete = baseMapper.deleteById(id);
        if(delete==0){
            throw new GuliException(20001,"删除课程失败");
        }

    }
}
